package org.jinghouyu.caculator.engine.expression;

import org.jinghouyu.caculator.engine.Expression;
import org.jinghouyu.caculator.engine.ExpressionException;

/**
 * 值表达式，表示一个值
 * @author liujingyu
 *
 */
public class ValueExpression extends Expression {

	private Object value;
	
	public ValueExpression(Object value) {
		this.value = value;
	}

	@Override
	protected Object _caculate(Object... values) {
		if(!(values == null || values.length == 0)) {
			throw new ExpressionException("值表达式的参数应该为空");
		}
		return value;
	}
	
	public String toString() {
		if(value instanceof Number) {
			Number n = (Number) value;
			if(n.longValue() == n.doubleValue()) {
				return n.longValue() + "";
			} else {
				return n.doubleValue() + "";
			}
		}
		return value + "";
	}
}